﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Collections;

namespace Agresso.Interface.Layer.Domain
{
    public class Invoice
    {
        //Header
        public string Client = "";
        public string CompanyCode = "";
        public string SupplierId = "";
        public string SupplierName = "";
        public string VatId = "";
        public string TaxNo = "";
        public DateTime Scandate = new DateTime(2000, 1, 1);
        public string DocumentType = "";
        public DateTime InvoiceDate = new DateTime(2000, 1, 1);
        public string InvoiceNumber = "";
        public decimal Netamount = 0;
        public decimal Vatrate = 0;
        public decimal Vatamount = 0;
        public decimal Totalamount = 0;
        public string Currency = "";
        //Line---------
        public string line_no = "";
        public string PONo = "";
        public string POPosition = "";
        public string Description = "";
        public string DeliveryNoteNo = "";
        public decimal Total = 0;
        public decimal Quantity = 0;
        public decimal Unitprice = 0;
        public string Unit = "";
        //-----middle layer ID
        public string FileName = "";
        public DateTime CreatedDate = new DateTime(2000, 1, 1);
        public DateTime ModifiedDate = new DateTime(2000, 1, 1);
        public string pickup_flag = "";
        public string batch_id = "";
        public int id = 0;
       
        public IList LineItems = new ArrayList();
        public Invoice() { }
        public Invoice(SqlDataReader rd)
        {
             //Header
            Client = DataConversion.ConvertToString(rd, "Client");
            CompanyCode = DataConversion.ConvertToString(rd, "CompanyCode");
            SupplierId = DataConversion.ConvertToString(rd, "SupplierId");
            SupplierName = DataConversion.ConvertToString(rd, "SupplierName");
            VatId = DataConversion.ConvertToString(rd, "VatId");
            TaxNo = DataConversion.ConvertToString(rd, "TaxNo");
            Scandate = DataConversion.ConvertToDateTime(rd, "Scandate");
            DocumentType = DataConversion.ConvertToString(rd, "DocumentType");
            InvoiceDate = DataConversion.ConvertToDateTime(rd, "InvoiceDate");
            InvoiceNumber = DataConversion.ConvertToString(rd, "InvoiceNumber");
            Netamount = DataConversion.ConvertToDecimal(rd, "Netamount");
            Vatrate = DataConversion.ConvertToDecimal(rd, "Vatrate");
            Vatamount = DataConversion.ConvertToDecimal(rd, "Vatamount");
            Totalamount = DataConversion.ConvertToDecimal(rd, "Totalamount");
            Currency = DataConversion.ConvertToString(rd, "Currency");
            //Line---------
            line_no = DataConversion.ConvertToString(rd, "line_no");
            PONo = DataConversion.ConvertToString(rd, "PONo");
            POPosition = DataConversion.ConvertToString(rd, "POPosition");
            Description = DataConversion.ConvertToString(rd, "Description");
            DeliveryNoteNo = DataConversion.ConvertToString(rd, "DeliveryNoteNo");
            Total = DataConversion.ConvertToDecimal(rd, "Total");
            Quantity = DataConversion.ConvertToDecimal(rd, "Quantity");
            Unitprice = DataConversion.ConvertToDecimal(rd, "Unitprice");
            Unit = DataConversion.ConvertToString(rd, "Unit");
            //--
            id = DataConversion.ConvertToInt32(rd, "id");
            CreatedDate = DataConversion.ConvertToDateTime(rd, "CreatedDate");
            ModifiedDate = DataConversion.ConvertToDateTime(rd, "ModifiedDate");
            pickup_flag = DataConversion.ConvertToString(rd, "pickup_flag");
            batch_id = DataConversion.ConvertToString(rd, "batch_id");
        }
        public void AddItem(Invoice item)
        {
            item.Client = Client;
            item.CompanyCode = CompanyCode;
            item.SupplierId = SupplierId;
            item.SupplierName = SupplierName;
            item.VatId = VatId;
            item.TaxNo = TaxNo;
            item.Scandate = Scandate;
            item.DocumentType = DocumentType;
            item.InvoiceDate = InvoiceDate;
            item.InvoiceNumber = InvoiceNumber;
            item.Netamount = Netamount;
            item.Vatrate = Vatrate;
            item.Vatamount = Vatamount;
            item.Totalamount = Totalamount;
            item.Currency = Currency;

            item.FileName = FileName;

            LineItems.Add(item);
        }
    }
}
